use ggez::{Context, GameResult, GameError, graphics};
use ggez::mint::Point2;
use glam::Vec2;

const ZERO: Vec2 = Vec2{x: 400.0, y : 300.0};
pub struct State{
}

impl State{
    pub fn new() -> State {
        State{}
    }
}

impl ggez::event::EventHandler<GameError> for State {
    fn update(&mut self, _ctx: &mut Context) -> GameResult {
        Ok(())
    }
    fn draw(&mut self, ctx: &mut Context) -> GameResult {
        let target = ctx.mouse.position();

        let target = Vec2 { x: target.x, y: target.y };
        let mut result = target-ZERO;
        result *= 0.5;
        result += ZERO;

        let mut canvas = graphics::Canvas::from_frame(ctx, graphics::Color::WHITE);

        let line = graphics::Mesh::new_line(
                ctx,
                &[Point2{x: ZERO.x, y: ZERO.y}, Point2{x:result.x, y: result.y}],
                2.0,
                graphics::Color::BLACK,
        )?;
        canvas.draw(&line, graphics::DrawParam::default());
        canvas.finish(ctx)?;
        Ok(())
    }
}